package main.java;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;

public class FileEncodingConvert {
    static String base = "";
    static String directory = "./DesignPattern/src/com/atguigu/patterns/state/money";

    public static void main(String[] args) throws Exception {
        File[] files = new File(base + directory).listFiles();
        assert files != null;
        for (File listFile : files) {
            if (!listFile.isFile()) {
                return;
            }
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(Files.newInputStream(listFile.toPath()), "GBK"));
            StringBuilder stringBuilder = new StringBuilder();
            String s = bufferedReader.readLine() + "\n";
            while (s != null ){
                stringBuilder.append(s).append("\n");
                s = bufferedReader.readLine();
            }
            bufferedReader.close();
            BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(listFile), StandardCharsets.UTF_8));
            bufferedWriter.write(stringBuilder.toString());
            bufferedWriter.close();
        }
    }

}
